export function getParent(el) {
    let parent = el.parentNode;

    if (!(parent instanceof Element)) {
        throw new Error('parentNode property of overflow must be auto or scroll');
    }
    while (parent && !(
        ['auto', 'scroll'].includes(getComputedStyle(parent).overflow) ||
        ['auto', 'scroll'].includes(getComputedStyle(parent).overflowX) ||
        ['auto', 'scroll'].includes(getComputedStyle(parent).overflowY)
    )) {
        parent = parent.parentNode;
        if (!(parent instanceof Element)) {
            throw new Error('parentNode property of overflow must be auto or scroll');
        }
    }

    return parent;
}


export function loadImg(src) {
    const img = new Image();
    img.setAttribute('src', src);

    return new Promise((resolve, reject) => {
        img.onload = resolve;
        img.onerror = reject;
    });
}


export function throttle(fn, duration = 50) {
    let st = Date.now();

    return function () {
        const now = Date.now();
        if (now - st >= duration) {
            st = now;
            return fn.apply(this, arguments);
        }
    };
}